<template>
  <div>
    <basic-container>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>产品配置</el-breadcrumb-item>
        <el-breadcrumb-item>新用户天数</el-breadcrumb-item>
      </el-breadcrumb>
    </basic-container>
    <basic-container>
      <avue-crud
        :table-loading="loading"
        ref="crud"
        :data="data"
        v-model="form"
        :option="option"
        :defaults.sync="defaults"
        :page.sync="page"
        @on-load="getData"
        @refresh-change="refreshChange"
        @search-reset="from = {}"
        @search-change="searchChange"
      >
        <template slot-scope="scope" slot="last_operation_info">
          <div class="authorId">
            {{ scope.row.edit_time }}
            <el-tag>{{ scope.row.edit_admin_name }}</el-tag>
          </div>
        </template>
        <template slot-scope="scope" slot="menu">
          <el-button 
          type="primary" 
          size="medium"
          @click="valueChange(scope.row)"
            >保存</el-button
          >
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import { common } from "@/api/cat/httpRequest";
import { catUrl } from "@/config/env";
import { newUserConfig as baseURL } from "@/api/cat/baseUrls";

export default {
  data() {
    return {
      page: {
        total: 0,
        pageSize: 10,
      },
      type: true,
      data: [],
      params: {},
      form: {},
      option: {
        addBtn: false,
        delBtn: false,
        editBtn: false,
        cancelBtn:false,
        border: true,
        column: [
          {
            label: "新用户时间范围（天）",
            prop: "config_value",
            type: "input",
            span: 24,
            cell: true,
            rules: [
              {
                required: true,
                message: "天数须填写",
              },
            ],
          },
          {
            label: "文案",
            prop: "content",
            type: "input",
            span: 24,
          },
          {
            label: "操作信息",
            prop: "last_operation_info",
            type: "input",
            slot: true,
          },
        ],
      },
    };
  },
  methods: {
    /**获取数据 */
    async getData() {
      console.log(111);
      this.loading = true;
      //清空表格列表
      this.data = [];
      //发送请求获取数据
      let response = await common(baseURL.get, null, null, "POST");
      let item = response.data;
      item.$cellEdit = true
      item.content =
        "在n天内出现的id均为新用户，享受新用户推书配置。此配置仅针对推荐位生效，不做其他作用。";
      this.data = [item];
      this.loading = false;
      console.log(this.data);
    },
    /**修改数据 */
    async valueChange(row) {
      let userInfo = this.$store.state.user.userInfo;
      row.edit_admin_name = userInfo.username;
      row.edit_admin_id = userInfo.id;
      row.value = row.config_value;
      let data = await common(`${baseURL.save}`, row, null, "POST");
      if (data == null) {
        return;
      }
      this.getData();
      done();
    },
  },
  mounted() {},
};
</script>
<style lang="scss" scoped></style>
